//
//  UIBarButtonItem + Extension.swift
//  Weibo10
//
//以按钮的方式添加监听方法抽取的构造函数

import UIKit

extension UIBarButtonItem {
    
    /// 遍历构造函数
    ///
    /// - parameter imageName:  图像名
    /// - parameter target:     监听对象
    /// - parameter actionName: 监听图像名
    ///
    /// - returns: UIBarButtonItem
    
    convenience init(imageName: String, target: AnyObject?, actionName: String?) {
        let button = UIButton(imageName: imageName, backImageName: nil )
        
        //判断 actionName
        if let actionName = actionName {
        
            button.addTarget(target, action: Selector(actionName), forControlEvents: .TouchUpInside)
        }
      self.init(customView: button)
    }
}
